package com.wsl.service.login;

import com.alibaba.fastjson.JSONObject;
import com.wsl.Date.DateUtil;
import com.wsl.Date.DateUtilTwo;
import com.wsl.Jwt.JwtUtil;
import com.wsl.MD5.MD5Utils;
import com.wsl.Uuid.UuidUtils;
import com.wsl.dao.UserDao;
import com.wsl.entity.user.User;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;


import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.List;

/**
 * @Author: wsl
 * @Date: 2022/3/26 11:09
 */


@Service
public class LoginService extends JwtUtil {

    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    UserDao userDao;

    private static final Integer STATUS_A = 1;
    private static final Integer STATUS_B = -1;




    //用户登入
    public int userLogin(String userName,String password) throws UnsupportedEncodingException {

        User user = userDao.findByUsername(userName);

        //账号密码错误
        String s = MD5Utils.md5(password, user.getSalt());
        if (!s.equals(user.getPassword())&&!user.getUsername().equals(userName)) {
            return STATUS_B;
        }

        return STATUS_A;
    }

    // 忘记密码-修改密码
    public int forgetPassword(String email){
return 1;
    }



}